<?php
header("HTTP/1.1 200 OK");
error_reporting(0);
define("DIR", dirname(__FILE__));
function randKey($len) {
    $chars = array(
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z",
        "0",
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9"
    );
    $charsLen = count($chars) - 1;
    shuffle($chars);
    $str = "";
    for ($i = 0; $i < $len; $i++) {
        $str.= $chars[mt_rand(0, $charsLen) ];
    }
    return $str;
}
function rdomain($d) {
    $provace = array();
    return str_replace("*", dechex(date("s") . mt_rand(1111, 9999)) . $provace[rarray_rand($provace) ], $d);
}
function rarray_rand($arr) {
    return mt_rand(0, count($arr) - 1);
}
function varray_rand($arr) {
    return $arr[rarray_rand($arr) ];
}
function get_folder_files($folder) {
    $fp = opendir($folder);
    while (false != $file = readdir($fp)) {
        if ($file != '.' && $file != '..') {
            $file = "$file";
            $arr_file[] = $file;
        }
    }
    closedir($fp);
    return $arr_file;
}
$key = $_SERVER["HTTP_USER_AGENT"];
$baiduspider = stripos($key, 'Baiduspider');
if (stripos($key, 'Googlebot') !== false || stripos($key, 'bingbot') !== false || stripos($key, 'MJ12bot') !== false || stripos($key, 'AhrefsBot') !== false || stripos($key, 'DNSPod-Monitor') !== false || stripos($key, 'BLEXBot') !== false || stripos($key, 'EasouSpider') !== false || stripos($key, 'YandexBot') !== false) {
    header("HTTP/1.1 503 Service Temporarily Unavailable");
    echo "对不起，页面维护中，请稍后访问！ \r\n版权所有：404站群网";
    exit;
} else {
    $timeout = 2592000;
    require DIR . '/mconfig.php';
    include DIR . "/mdirCache.class.php";
    $cache = new dirCache();
    $mydomain = $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
    if ($cache->isExists($mydomain, $timeout)) {
        $moban = $cache->get($mydomain);
        $zf1 = count(explode('<404_动态随机字符>', $moban)) - 1;
        for ($ii = 0; $ii < $zf1; $ii++) {
            $moban = preg_replace('/<404_动态随机字符>/', randKey(5) , $moban, 1);
        }
        $ri5 = count(explode('<404_动态随机数字>', $moban)) - 1;
        for ($i = 0; $i < $ri5; $i++) {
            $moban = preg_replace('/<404_动态随机数字>/', mt_rand(10000, 99999) , $moban, 1);
        }
        $moban = str_replace("<404_动态当天时间>", date("Y-m-d") , $moban);
        $ci = count(explode('<404_动态随机关键词>', $moban)) - 1;
        if ($ci != 0) {
            $keywords = $bak_keywords = file(DIR . "/mm404seo/keywords/" . varray_rand($keyword_list));
            for ($ii = 0; $ii < $ci; $ii++) {
                $moban = preg_replace('/<404_动态随机关键词>/', trim(varray_rand($keywords)) , $moban, 1);
            }
        }
        $wk = count(explode('<404_动态句子>', $moban)) - 1;
        if ($wk != 0) {
            $juzi = $bak_juzi = file(DIR . "/m404seo/juzi/" . varray_rand($wenku_list));
            for ($wi = 0; $wi < $wk; $wi++) {
                $moban = preg_replace('/<404_动态句子>/', trim(varray_rand($juzi)) , $moban, 1);
            }
        }
        $wk = count(explode('<404_动态句子2>', $moban)) - 1;
        if ($wk != 0) {
            $juzi2 = $bak_juzi2 = file(DIR . "/m404seo/juzi2/" . varray_rand($wenku_list2));
            for ($wi = 0; $wi < $wk; $wi++) {
                $moban = preg_replace('/<404_动态句子2>/', trim(varray_rand($juzi2)) , $moban, 1);
            }
        }
        $spider = $bak_spider = file(DIR . "/m404seo/spider/" . varray_rand($spider_link));
        $wk = count(explode('<spider>', $moban)) - 1;
        for ($wi = 0; $wi < $wk; $wi++) {
            $moban = preg_replace('/<spider>/', trim(varray_rand($spider)) , $moban, 1);
        }
        $moban = preg_replace('/<spider>/', '', $moban, 1);
        echo $moban;
        exit();
    }
    $template_list = get_folder_files(DIR . '/m404seo/templates/shouye/');
    $keywords = $bak_keywords = file(DIR . "/m404seo/keywords/" . varray_rand($keyword_list));
    $juzi = $bak_juzi = file(DIR . "/m404seo/juzi/" . varray_rand($wenku_list));
    $juzi2 = $bak_juzi2 = file(DIR . "/m404seo/juzi2/" . varray_rand($wenku_list2));
    $spider = $bak_spider = file(DIR . "/m404seo/spider/" . varray_rand($spider_link));
    $domains = $bak_domains = file(DIR . "/m404seo/domains/" . varray_rand($domain_list));
    $moban = file_get_contents(DIR . "/m404seo/templates/shouye/" . varray_rand($template_list));
    function getdomain($url) {
        $host = strtolower($url);
        if (strpos($host, '/') !== false) {
            $parse = @parse_url($host);
            $host = $parse['host'];
        }
        $topleveldomaindb = array(
            'gov.cn',
            'com.cn',
            'net.cn',
            'org.cn',
            'com',
            'cn',
            'asia',
            'edu',
            'gov',
            'ga',
            'net',
            'org',
            'biz',
            'info',
            'pw',
            'name',
            'mobi',
            'cc',
            'hk'
        );
        $str = '';
        foreach ($topleveldomaindb as $v) {
            $str.= ($str ? '|' : '') . $v;
        }
        $matchstr = "[^\.]+\.(?:(" . $str . ")|\w{2}|((" . $str . ")\.\w{2}))$";
        if (preg_match("/" . $matchstr . "/ies", $host, $matchs)) {
            $domain = $matchs['0'];
        } else {
            $domain = $host;
        }
        return $domain;
    }
    $duankou = $_SERVER["SERVER_PORT"];
    $url1 = $_SERVER['REQUEST_URI'];
    $yuming = $_SERVER['HTTP_HOST'];
    $yuming = str_replace(':' . $duankou, '', $yuming);
    $yumi = getdomain($yuming);
    $url2 = str_replace('.' . $yumi, '', $yuming);
    $duankous = file(DIR . "/m404seo/duankou/duankous.txt");
    $miaoshus = file(DIR . "/m404seo/miaoshu/miaoshu.txt");
    $miaoshu = count(explode('<404_描述>', $moban)) - 1;
    for ($sp = 0; $sp < $miaoshu; $sp++) {
        $moban = preg_replace('/<404_描述>/', trim(varray_rand($miaoshus)) , $moban, 1);
    }
    $gjc1 = trim(varray_rand($keywords));
    $gjc2 = trim(varray_rand($keywords));
    $gjc3 = trim(varray_rand($keywords));
    $gjc4 = trim(varray_rand($keywords));
    $gjc5 = trim(varray_rand($keywords));
    $gjc6 = trim(varray_rand($keywords));
    $moban = str_replace("<404_主关键词>", $gjc1, $moban);
    $moban = str_replace("<404_关键词2>", $gjc2, $moban);
    $moban = str_replace("<404_关键词3>", $gjc3, $moban);
    $moban = str_replace("<404_关键词4>", $gjc4, $moban);
    $moban = str_replace("<404_关键词5>", $gjc5, $moban);
    $moban = str_replace("<404_关键词6>", $gjc6, $moban);
    $ci = count(explode('<404_随机关键词>', $moban)) - 1;
    for ($ii = 0; $ii < $ci; $ii++) {
        $moban = preg_replace('/<404_随机关键词>/', trim(varray_rand($keywords)) , $moban, 1);
    }
    $wk = count(explode('<404_句子>', $moban)) - 1;
    for ($wi = 0; $wi < $wk; $wi++) {
        $moban = preg_replace('/<404_句子>/', trim(varray_rand($juzi)) , $moban, 1);
    }
    $wk2 = count(explode('<404_指数词>', $moban)) - 1;
    for ($wi2 = 0; $wi2 < $wk2; $wi2++) {
        $moban = preg_replace('/<404_指数词>/', trim(varray_rand($juzi2)) , $moban, 1);
    }
    $dk = count(explode('<404_随机端口>', $moban)) - 1;
    for ($di = 0; $di < $dk; $di++) {
        $moban = preg_replace('/<404_随机端口>/', trim(varray_rand($duankous)) , $moban, 1);
    }
    $vi = count(explode("<404_随机外链>", $moban)) - 1;
    for ($li = 0; $li < $vi; $li++) {
        $s = trim(varray_rand($domains));
        $moban = preg_replace('/<404_随机外链>/', $s, $moban, 1);
    }
    $zf1 = count(explode('<404_随机字符>', $moban)) - 1;
    for ($ii = 0; $ii < $zf1; $ii++) {
        $moban = preg_replace('/<404_随机字符>/', randKey(5) , $moban, 1);
    }
    $ri5 = count(explode('<404_随机数字>', $moban)) - 1;
    for ($i = 0; $i < $ri5; $i++) {
        $moban = preg_replace('/<404_随机数字>/', mt_rand(10000, 99999) , $moban, 1);
    }
    $moban = str_replace("<404_当前域名>", $yuming, $moban);
    $moban = str_replace("<404_顶级域名>", $yumi, $moban);
    $moban = str_replace("<404_当前域名1>", $_SERVER['HTTP_HOST'], $moban);
    $tupian5 = count(explode('<404_随机图片>', $moban)) - 1;
    for ($tui = 0; $tui < $tupian5; $tui++) {
        $moban = preg_replace('/<404_随机图片>/', '/pics/' . varray_rand($image_list) , $moban, 1);
    }
    $moban = str_replace("<404_年>", date("y") , $moban);
    $moban = str_replace("<404_发布时间>", date("m-d") , $moban);
    $moban = str_replace("<404_发布时间1>", date("m-d", strtotime("-1 day")) , $moban);
    $moban = str_replace("<404_发布时间2>", date("m-d", strtotime("-2 day")) , $moban);
    $moban = str_replace("<404_发布时间3>", date("m-d", strtotime("-3 day")) , $moban);
    $moban = str_replace("<404_发布时间4>", date("m-d", strtotime("-4 day")) , $moban);
    $moban = str_replace("<404_发布时间5>", date("m-d", strtotime("-5 day")) , $moban);
    $moban = str_replace("<404_发布时间6>", date("m-d", strtotime("-6 day")) , $moban);
    $moban = str_replace("<404_发布时间7>", date("m-d", strtotime("-7 day")) , $moban);
    $moban = str_replace("<404_发布时间8>", date("m-d", strtotime("-8 day")) , $moban);
    $moban = str_replace("<404_发布时间9>", date("m-d", strtotime("-9 day")) , $moban);
    $moban = str_replace("<404_发布时间10>", date("m-d", strtotime("-10 day")) , $moban);
    $moban = str_replace("<404_发布时间11>", date("m-d", strtotime("-11 day")) , $moban);
    $moban = str_replace("<404_发布时间12>", date("m-d", strtotime("-12 day")) , $moban);
    $moban = str_replace("<404_发布时间13>", date("m-d", strtotime("-13 day")) , $moban);
    $moban = str_replace("<404_发布时间14>", date("m-d", strtotime("-14 day")) , $moban);
    $moban = str_replace("<404_发布时间15>", date("m-d", strtotime("-15 day")) , $moban);
    $moban = str_replace("<404_发布时间16>", date("m-d", strtotime("-16 day")) , $moban);
    $moban = str_replace("<404_发布时间17>", date("m-d", strtotime("-17 day")) , $moban);
    $moban = str_replace("<404_发布时间18>", date("m-d", strtotime("-18 day")) , $moban);
    $moban = str_replace("<404_发布时间19>", date("m-d", strtotime("-19 day")) , $moban);
    $moban = str_replace("<404_发布时间20>", date("m-d", strtotime("-20 day")) , $moban);
    $moban = str_ireplace("</body>", "" . "</body>", $moban);
    if (stripos($key, 'Spider') == false && stripos($key, 'bot') == false) {
        $zhizhu = "jia";
    } else {
        $zhizhu = "zhen";
    }
    if ($baiduspider !== false) {
        $cache->set($mydomain, $moban);
    } else {
        if ($zhizhu == "jia") {
            $cache->set($mydomain, $moban);
        }
    }
    $zf1 = count(explode('<404_动态随机字符>', $moban)) - 1;
    for ($ii = 0; $ii < $zf1; $ii++) {
        $moban = preg_replace('/<404_动态随机字符>/', randKey(5) , $moban, 1);
    }
    $ri5 = count(explode('<404_动态随机数字>', $moban)) - 1;
    for ($i = 0; $i < $ri5; $i++) {
        $moban = preg_replace('/<404_动态随机数字>/', mt_rand(10000, 99999) , $moban, 1);
    }
    $moban = str_replace("<404_动态当天时间>", date("Y-m-d") , $moban);
    $ci = count(explode('<404_动态随机关键词>', $moban)) - 1;
    for ($ii = 0; $ii < $ci; $ii++) {
        $moban = preg_replace('/<404_动态随机关键词>/', trim(varray_rand($keywords)) , $moban, 1);
    }
    $wk = count(explode('<404_动态句子>', $moban)) - 1;
    for ($wi = 0; $wi < $wk; $wi++) {
        $moban = preg_replace('/<404_动态句子>/', trim(varray_rand($juzi)) , $moban, 1);
    }
    $wk = count(explode('<404_动态句子2>', $moban)) - 1;
    if ($wk != 0) {
        $juzi2 = $bak_juzi2 = file(DIR . "/m404seo/juzi2/" . varray_rand($wenku_list2));
        for ($wi = 0; $wi < $wk; $wi++) {
            $moban = preg_replace('/<404_动态句子2>/', trim(varray_rand($juzi2)) , $moban, 1);
        }
    }
    $wk = count(explode('<spider>', $moban)) - 1;
    for ($wi = 0; $wi < $wk; $wi++) {
        $moban = preg_replace('/<spider>/', trim(varray_rand($spider)) , $moban, 1);
    }
    $moban = preg_replace('/<spider>/', '', $moban, 1);
    echo $moban;
    function nowtime() {
        $date = date("Y-m-d.G:i:s");
        return $date;
    }
}
include 'mbot/bot.php';
?>
